package com.stone.db.jdbc.service.impl;

import com.stone.db.jdbc.entity.DriverRecord;
import com.stone.db.jdbc.mapper.DriverRecordMapper;
import com.stone.db.jdbc.service.DriverRecordService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>Created with IntelliJ IDEA. </p>
 * <p>User: Stony </p>
 * <p>Date: 2016/6/27 </p>
 * <p>Time: 18:06 </p>
 * <p>Version: 1.0 </p>
 */
@Service("driverRecordService")
public class DriverRecordServiceImpl implements DriverRecordService {

    @javax.annotation.Resource
    DriverRecordMapper driverRecordMapper;

    @Override
    public List<DriverRecord> queryAll() {
        return driverRecordMapper.selectAll();
    }

    @Override
    public DriverRecord queryRecordById(int id) {
        List<DriverRecord> list = driverRecordMapper.queryRecordById(id);
        if(list != null && list.size() >= 1){
            return list.get(0);
        }
        return null;
    }

    @Override
    public DriverRecord save(DriverRecord record) {
        driverRecordMapper.insert(record);
        return record;
    }

    @Override
    public DriverRecord update(DriverRecord record) {
        driverRecordMapper.update(record);
        return record;
    }

    @Override
    public int delete(int id) {
        return driverRecordMapper.delete(id);
    }

    @Override
    public DriverRecord queryRecordByDate(Date date) {
        List<DriverRecord> list = driverRecordMapper.queryRecordByDate(date);
        if(list != null && list.size() >= 1){
            return list.get(0);
        }
        return null;
    }
}
